package Class;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * @Author czl
 * @Date 2024-03-25
 */
public class MainTest {
    public static void main(String[] args) throws Exception {

        //第一：获取类的 Class 对象
        //方法一:
        Class<?> clazz = Class.forName("Class.Student");
        //方法二:
        //Class<?> studentClass = Student.class;

        Constructor<?>[] constructors = clazz.getConstructors();

        for (Constructor<?> constructor : constructors) {
            //System.out.println(constructor);
        }

        Constructor<?> constructor = clazz.getConstructor(String.class, int.class, Double.class);
        Object obj = constructor.newInstance("张三", 18, 80D);

        if(obj instanceof Student) {
            Student stu = (Student) obj ;
            stu.show();
        }


        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {

            String string = Modifier.toString(field.getModifiers());
            String name = field.getType().getName();
            String name1 = field.getName();

            //System.out.println(string + " " + name + " " + name1);
        }


        Field[] fields1 = clazz.getDeclaredFields();
        for (Field field : fields1) {
            String string = Modifier.toString(field.getModifiers());
            String simpleName = field.getType().getSimpleName();




            //System.out.println(string + " " + simpleName + " "  );
        }

        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            System.out.println(method.getName());
        }
    }
}
